<?php
/*
Copyright 2008, Nathalia


Author:
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)

*/
class Detalhes extends TPage
{
	private $_anais;
	public function onInit($param)
	{
		parent::onInit($param);
        $anaisID = (int)$this->Request['anaisID'];
        $this->_anais = AnaisRecord::finder()->findByAnaisID($anaisID);
        if($this->_anais === null)  
            throw new THttpException(500,'Nao foi possivel encontrar o anais especificada.');
        $this->Anais->Nome = $this->_anais->Nome;
        $this->Anais->Editora = $this->_anais->Editora;
        $this->Anais->Status = $this->_anais->Status;
        $this->Anais->CongressoID = $this->_anais->CongressoID;

        if(!$this->IsPostBack)  // if the page is requested the first time
        {
            // populates post data into the repeater
            $this->populateData();
        }
	}

    public function getAnais()
    {
        return $this->_anais;
    }

    public function status($status)
    {
        if($status == 0)
            return "Pendente";
        else if($status == 1)
            return "Publicado";
    }

    public function deleteAnais($sender,$param)
    {
        if(!$this->User->IsAdmin)
            throw new THttpException('Voce nao pode realizar essa acao.');
        $this->_anais->delete();
        $this->Response->redirect("./index.php?page=Anais.Listar");
    }

 
    protected function populateData()
    {
        $this->Repeater->DataSource = $this->getArtigos();
        $this->Repeater->dataBind();
    }

    protected function getArtigos()
    {   
        $criteria                       = new TActiveRecordCriteria;
        $criteria->OrdersBy['Titulo'] = 'asc';
        $criteria->Condition = 'CongressoID = '.$this->Anais->CongressoID." AND Status = 1";
        // query for the posts with the above criteria and with author information
        return ArtigoRecord::finder()->findAll($criteria);

    }


}
?>
